package com.bankLogisticsSys.service;

import com.bankLogisticsSys.model.Business;
import com.bankLogisticsSys.model.Expresspath;
import com.bankLogisticsSys.model.Networkinfo;

public class TransformService {
	public static String getAction(int a){
		String action;
		switch(a){
		case 0: action = "揽收（分发）";break;
		case 1: action = "发送";break;
		case 2: action = "接收";break;
		case 3: action = "派单";break;
		case 4: action = "验收";break;
		default:action = "异常";
		}
		return action;
		
	}
//	表驱动法
//	public static String getActionT(int a){
//		String[] action = {"揽收","发送","接收","派单","验收"};
//		return action[a];
//	}
	
	public static String getActionEN(int a){
		String action;
		switch(a){
		case 0: action = "get";break;
		case 1: action = "send";break;
		case 2: action = "receive";break;
		case 3: action = "pack";break;
		case 4: action = "accept";break;
		default:action = "error";
		}
		return action;
		
	}
	
	public static String getPackageType(int type){
		String t;
		switch(type){
		case 0:t="小包";break;
		case 1:t="大包";break;
		default:t= "";
		}
		return t;
	}
	
	public static int getTagByRole(int role){
		int tag = 2;
		switch(role){
		case 1:tag=100;break;
		case 2:tag=101;break;
		case 3:tag=102;break;
		case 4:tag=103;break;
		case 5:tag=104;break;
		default:tag = 2;
		}
		return tag;
	}
	
	public static String getNetwork(int networkID){
		Networkinfo ni = Networkinfo.dao.findFirst("select * from networkinfo where id = ?", networkID);
		if(ni!=null){
			return ni.getNetwork();
		}else{
			return "！！！本单不应经过本站";
		}
	}
	
	public static int getSequenceNetwork(int sequence, int source,int businessID,boolean flag){
		Expresspath ep = Expresspath.dao.findFirst("select * from expresspath where networkid = ? and sequence = ? and businessID=? and flag=?", source, sequence,businessID,flag);
		if(ep!=null){
			return ep.getPathID();
		}
		return 0;
	}
	
	public static int getSequence(int path, int source, int businessID){
		System.out.println("businessID is " + businessID);
		Expresspath ep = Expresspath.dao.findFirst("select * from expresspath where networkid = ? and pathid = ? and businessID = ?", source, path, businessID);
		if(ep!=null){
			return ep.getSequence();
		}else{
			return -1;
		}
	}
	
	public static int getDestination(int networkid){
		Networkinfo ni = Networkinfo.dao.findFirst("select * from networkinfo where id = ?", networkid);
		return ni.getSuperiorID();
	}

	public static String getBusiness(Integer businessID) {
		Business b = Business.dao.findFirst("select * from business where businessID = ?", businessID);
		return b.getBusiness();
	}
}
